package models

import "github.com/astaxie/beego/orm"

type TradeData struct {
	Id            int    `orm:"pk;auto"`
	StoreCode     string `orm:"size(32);null;index"`
	TableCode     string `orm:"size(32);null;index"`
	CreateTime    string `orm:"size(32);null;index"`
	PayTime       string `orm:"size(32);null;index"`
	PayAmount     int    `orm:"size(32);null"`
	StoreName     string `orm:"size(64);null"`
	TradeNo       string `orm:"size(64);null;index"`
	UpTradeNo     string `orm:"size(64);null;index"`
	DownTradeNo   string `orm:"size(64);null;index"`
	HasPush       string `orm:"size(32);null"`
	BuyerUserId   string `orm:"size(32);null"`
	BuyerUserName string `orm:"size(32);null"`
	RequestId     string `orm:"size(32);null"` //推送唯一码
	//业务模块
	TradeStatus   string `orm:"size(32);null;index"`
	TradeChannel  string `orm:"size(32);null;index"`
	ReceiptAmount int    `orm:"size(32);null"`
	BuyerAmount   int    `orm:"size(32);null"`
	OpenId        string `orm:"size(32);null"`
	SubOpenId     string `orm:"size(32);null"`
	RawData       string `orm:"size(64);null"`
}

func (this *TradeData) TableEngine() string {
	return "INNODB"
}

//菜单对象重写表名称方法,此处可以自定义表名称
func (m *TradeData) TableName() string {
	return "trade_data"
}

func (this *TradeData) Insert() error {
	if _, err := orm.NewOrm().Insert(this); err != nil {
		return err
	}
	return nil
}

func (this *TradeData) Update(fields ...string) error {
	if _, err := orm.NewOrm().Update(this, fields...); err != nil {
		return err
	}
	return nil
}

func (this *TradeData) Read(fields ...string) error {
	if err := orm.NewOrm().Read(this, fields...); err != nil {
		return err
	}
	return nil
}

func (this *TradeData) Delete() error {
	if _, err := orm.NewOrm().Delete(this); err != nil {
		return err
	}
	return nil
}

func init() {
	orm.RegisterModel(new(TradeData))
}
